package com.rd.student.jiaji.class3.wangyanbo.day0829;

import java.util.Arrays;

public class Test1 {
    public static void main(String[] args) {
        int[] array = new int[]{1, 2, 3, 4, 5, 6, 7};
        rotate(array, 3);
        System.out.println(Arrays.toString(array));
    }
    public static void rotate(int[] nums, int k) {
        int i = 0;
        int j = nums.length - 1;
        int tam;
        if (nums.length < k) {
            k = k % nums.length;
        }
        while (i < j) {
            tam = nums[i];
            nums[i] = nums[j];
            nums[j] = tam;
            i++;
            j--;
        }
        i = 0;
        j = k - 1;
        while (i < j) {
            tam = nums[i];
            nums[i] = nums[j];
            nums[j] = tam;
            i++;
            j--;
        }
        i = k;
        j = nums.length - 1;
        while (i < j) {
            tam = nums[i];
            nums[i] = nums[j];
            nums[j] = tam;
            i++;
            j--;
        }
    }
}
